package com.carnation._synchronized_utility;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * <p>
 * ReentrantLock
 * </p>
 *
 * @author: zhu.chen
 * @date: 2021/3/22
 * @version: v1.0.0
 */
public class ReentrantLockTest {

    private final Lock lock = new ReentrantLock();

    public String getResource() throws InterruptedException {
        try {

            lock.tryLock(10, TimeUnit.SECONDS);
            return "ok";
        } finally {
            lock.unlock();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        ReentrantLockTest test = new ReentrantLockTest();
        System.out.println(test.getResource());
    }

}
